#include "OOPMutex.h"

using namespace OOPUtils;

OOPUtils::OOPMutex::OOPMutex (bool lockOnCreate)
{
	_hMutex = CreateMutex (NULL, lockOnCreate, NULL);
}

OOPMutex::~OOPMutex ()
{
}

OOPUtils::OOPMutex::ScopedLock::ScopedLock (OOPMutex &mutex) : _mutex (mutex)
{
	_mutex.lock ();
}

OOPUtils::OOPMutex::ScopedLock::~ScopedLock ()
{
	_mutex.unlock ();
}

void OOPUtils::OOPMutex::lock (DWORD waitTime)
{
	WaitForSingleObject (_hMutex, waitTime);
}

void OOPUtils::OOPMutex::unlock ()
{
	ReleaseMutex (_hMutex);
}